<DIV id="mainContainer">
	<DIV id="leftCol">
	</DIV>
	<DIV id="contentCol">
		
	
<?php
//$F=new Friends();
//$F->Get_friends($LOG);

$request = "select distinct id_msg, u1.pseudo as psto,u2.pseudo as psfrom, id_from, id_to, date_format(`date`,'%d/%m/%y %H:%i') as d, id_father, content 
from msg as m, user as u1, user as u2, friendship as f 
where f.id1 = \"".$_SESSION["info"]["id_user"]."\" and (m.id_to=f.id2 OR m.id_to=f.id1) and id_father=0 and u1.id_user=m.id_to and u2.id_user=m.id_from 
order by date desc limit 0,20";

$dbin = new DB();
$dbin->query($request);

$dbin->getrownumber();
if($dbin->nbrow==0){
		echo "No news! You should consider having more friends... Freak !";
}else{

	$j=1;
	while($dbin->fetch_assoc()){
		
			echo "<DIV class=\"storyContainer\">";
			
			if ($dbin->row['id_from']==$dbin->row['id_to']){
			
				echo "<a href=main.php?page=profil&S=".$dbin->row['id_from'].">".$dbin->row['psfrom']."</a>";
			}else{
				echo "<a href=main.php?page=profil&S=".$dbin->row['id_from'].">".$dbin->row['psfrom']."</a> => <a href=main.php?page=profil&S=".$dbin->row['id_to'].">".$dbin->row['psto']."</a>";
			}
			
			echo " <DIV class='firstMsg'>".$dbin->row['content']." <br/><DIV style='color: #999999;'>".$dbin->row['d']."</DIV></DIV>";
		
			echo "<DIV class='msgBox'>";
			$request2 = "select distinct pseudo, id_from, date_format(`date`,'%d/%m/%y %H:%i') as d, content from msg as m, user as u, friendship as f 
						where id_father = ".$dbin->row['id_msg']." and u.id_user=m.id_from 
						order by `date`";
					
			$dbin2 = new DB();
			$dbin2->query($request2);
		
			// it's a request in a request to get commentaries on commentaries
			while($dbin2->fetch_assoc()){
				echo "<DIV class='comment'><a href=main.php?page=profil&S=".$dbin2->row['id_from'].">".$dbin2->row['pseudo']." </a>".$dbin2->row['content']." <br/><DIV style='color: #999999;'> ".$dbin2->row['d']."</DIV></DIV>";
			}
			echo "<DIV class='comment'><form action=# method=\"post\" id=\"myForm\">" ;
			echo "<input type =\"hidden\" name = \"com".$j."\" value =\"".$dbin->row['id_msg']."\" /> ";
			echo "<input type =\"hidden\" name = \"pers".$j."\" value =\"".$dbin->row['id_to']."\" /> "; 	
			echo "<input type=\"text\" name=\"text".$j."\" value=\"\" size=\"45\" />";
			echo "<input class='fbbutton rfloat' type=\"submit\" name=\"val".$j."\" value=\"Comment\" /> ";
			echo "</form></DIV>	";
			echo "</DIV>";

			
			$j=$j+1;
			echo "</DIV><DIV class='fbcontentdivider'></DIV>";
	}
	
     for($i=1;$i < 21;$i++) 
     { 
          if(isset($_POST["val".$i])&& $_POST["text".$i]!=""){
		  
		  $request = "INSERT INTO msg (id_from, id_to,`date`,id_father,content)
					Values ('".$_SESSION["info"]["id_user"]."','".$_POST["pers".$i]."',now(),'".mysql_real_escape_string($_POST["com".$i])."',\"".mysql_real_escape_string($_POST["text".$i])."\")";
		  
		  $dbin->query($request);
		  
		  echo "<meta http-equiv='refresh' content='0;URL=main.php?page=home'>";
		  
		  }
     } 
}	 
	
	

?>
	</DIV>
</DIV>
